package com.iman.sumer.service.impl.teamgroup;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import com.iman.common.hibernate.TemplateQLService;
import com.iman.common.support.Page;
import com.iman.sumer.service.teamgroup.GroupTopicService;
import com.iman.sumer.vo.teamgroup.GroupTopicVo;

@Service
public class GroupTopicServiceImpl implements GroupTopicService {
	@Inject
    private TemplateQLService templateQLService;
	@Override
	public Page<GroupTopicVo> getGroupTopicList(Map<String, Object> params) {
		Integer ps = Integer.valueOf(params.get("ps").toString());
		Integer pn = Integer.valueOf(params.get("pn").toString());
		params.put("startNo", ps*pn);
 		Page<GroupTopicVo> vos = templateQLService.findByPagedSQLBeanQuery(
				"group_topic_list", params, Page.getStartOfPage(pn, ps), ps,
				GroupTopicVo.class);
		return vos;
	}

	@Override
	public Map getGroupTopicByID(Map params) {
		List<Map> vos = templateQLService.findBySQLMapQuery("topic_by_id", params);
		if(vos!=null && !vos.isEmpty()){
			return vos.get(0);
		}
		return null;
	}

	@Override
	public void addGroupTopic(Map<String, Object> params) {
		templateQLService.executeSQLUpdate("add_group_topic", params);
	}

	@Override
	public List<Map> getGroupTopicListTop3(Map<String, Object> params) {
		List<Map> map = this.templateQLService.findBySQLMapQuery("group_topic_list_top3", params);
		return map;
	}
	
	@Override
	public List<Map> getGroupTopicListNoPage(Map<String, Object> params) {
		List<Map> map = this.templateQLService.findBySQLMapQuery("group_topic_list", params);
		return map;
	}

	@Override
	public void deleteTopic(Map params) {
		templateQLService.executeSQLUpdate("topic_delete", params);
		
	}

	@Override
	public void updateTopic(Map params) {
		templateQLService.executeSQLUpdate("topic_update", params);
	}

	@Override
	public void updateTopicView(Map params) {
		templateQLService.executeSQLUpdate("topic_update_view", params);
	}


}
